<?php
namespace app\api\controller;

use app\lib\Show;
use think\Exception;
use think\response\Json;

class Order extends Auth {

    public function save() : Json{

        $params["address_id"] = $this->request->param("address_id", 0, "intval");
        $params["ids"] = $this->request->param("ids", "", "trim");
        if ($params["address_id"] <= 0 || $params["ids"] == "") {
            return Show::fail("获取参数失败");
        }
        try{
            $params["user_id"] = $this->user["id"];
            $params["ids"] = explode(",", $params["ids"]);
            $result = (new \app\api\business\Order())->save($params);
            if (empty($result)) {
                return Show::fail("提交订单失败");
            }

            return Show::success("提交订单成功", $result);
        }catch (Exception $e){
            return Show::fail($e->getMessage());
        }
    }

    public function detail($id = 0) : Json {
        if (empty($id)) {
            return Show::fail("获取参数失败");
        }
        try{
            $result = (new \app\api\business\Order())->detail($id);

            return Show::success("ok", $result);
        }catch (Exception $e){
            return Show::fail($e->getMessage());
        }
    }
}
